const { addcomment: MA,getCommentList:MG} = require('../model/comment')
const addcomment = async (req, res, next) => {
  const { userId,goodsId,comment_content } = req.body
  const result = await MA(userId-0,goodsId-0,comment_content)
  if (result === 0) return res.send({
    message: '添加失败, 你给我的商品 id 不存在',
    code: 0,
    tips: `你传递给我的 'goodsId' 是 : '${ goodsId }' ^_^`
  })

  res.send({
    message: '添加评论成功 ! O(∩_∩)O哈哈~',
    code: 1
  })
}

const getCommentList = async (req, res, next) => {
  const { goods_id } = req.query
  const result = await MG(goods_id-0)
  res.send({
    message: '获取留言列表成功',
    code: 1,
    yourParams: {
      msg: '这是你带来的参数, 我带回去给你看看 ^_^'
    },
    comment: result
  })
}


module.exports = {
  addcomment,
  getCommentList
}
